import {createRouter, createWebHistory} from 'vue-router'
import Layout from "@/layout/Index.vue";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'             the icon show in the sidebar
 noCache: true                if set true, the page will no be cached(default is false)
 affix: true                  if set true, the tag will affix in the tags-view
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

import home from '@/views/home/Home.vue'
import arch from '@/views/img/arch/Arch.vue'
import scenery from '@/views/img/scenery/Scenery.vue'
import sportscar from '@/views/img/sports-car/SportsCar.vue'

import antique from '@/views/collection/antique/Antique.vue'
import hetianjade from '@/views/collection/hetianjade/Hetianjade.vue'
import setting from '@/views/setting/Setting.vue'
import other from '@/views/other/Other.vue'


// 定义路由规则
const routers = [
    {
        path: "/home",
        component: Layout,
        children: [
            {
                path: "index",
                component: home,
                name: "Home",
                meta: {title: "首页", isTab: true}
            }
        ]
    },
    {
        path: "/img",
        component: Layout,
        children: [
            {
                path: "arch",
                component: arch,
                name: "arch",
                meta: {title: "建筑", isTab: true}
            }, {
                path: "Scenery",
                component: scenery,
                name: "Scenery",
                meta: {title: "风景", isTab: true}
            }, {
                path: "SportsCar",
                component: sportscar,
                name: "SportsCar",
                meta: {title: "跑车", isTab: true}
            }
        ]
    },
    {
        path: "/collection",
        component: Layout,
        children: [
            {
                path: "antique",
                component: antique,
                name: "Hntique",
                meta: {title: "古董", isTab: true}
            }, {
                path: "hetianjade",
                component: hetianjade,
                name: "Hetianjade",
                meta: {title: "和田玉", isTab: true}
            }
        ]
    },
    {
        path: '/setting',
        component: Layout,
        children: [
            {
                path: '',
                component: setting,
                name: "set",
                meta: {title: "设置", isTab: true}
            }
        ]
    },
    {
        path: "/other",
        component: Layout,
        children: [
            {
                path: "",
                component: other,
                name: "Other",
                meta: {title: "其他", isTab: true}
            }
        ]
    },


    {
        path: "/",
        redirect: "/home/index"
    },

];

import error_404 from '@/components/error-page/404.vue'
import error_401 from '@/components/error-page/401.vue'

/**
 * 错误页面
 */
const error_route = [
    {
        path: "/404",
        component: error_404,
        hidden: true
    },
    {
        path: "/401",
        component: error_401,
        hidden: true
    }
]


const router = createRouter({
    //mode: 'hash',三张模式：hash|history|abstract，默认hash
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [...routers, ...error_route]
});
// console.log("regis ")


/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
// export const asyncRoutes = [];
//
// const createRouter = () =>
//   new Router({
//     // mode: "history", // require service support
//     scrollBehavior: () => ({ y: 0 }),
//     routes: constantRoutes
//   });
//
// const router = createRouter();
// router.beforeEach((to, from, next) => {
//   next();
// });
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// export function resetRouter() {
//   const newRouter = createRouter();
//   router.matcher = newRouter.matcher; // reset router
// }
export default router;
